<?php

  //
  // Memorii Web
  // script/delete_folder.php
  //
  // Delete current folder
  //
  
  session_start();
  
  require_once('../const.php');
  require_once('../db/db.php');
  
  $folder_id = '0';
  if( isset($_SESSION['current_folder_id'])) {
  	$folder_id = $_SESSION['current_folder_id'];
  }
  
  $db_connection = db_connect();
  $folder_data = db_get_folder($db_connection, $folder_id);
  
  if(count($folder_data)==0) {
  	// Root folder: do not delete
  	echo '<div class="msg">Cannot delete root folder.</div>';
  }
  else {
	  // Go to parent folder
 	 $_SESSION['current_folder_id'] = $folder_data['parent_folder_id'];
  
	  // Delete 
	  db_delete_folder($db_connection, $folder_id);
	  
	  echo '<div class="msg">Folder deleted.</div>';
  }
  
  // Disconnect database
  db_disconnect($db_connection);

  include('../../content/folder.php');
?>